import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

/**
 * @author 86187
 * @classname ServletE2
 * @time 2024/4/1
 * @project javaweb_project
 */@WebServlet("/e")
public class ServletE extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        super.doGet(request, response);
        HttpSession session= request.getSession(true);
        System.out.println("ServletE的会话id:\t"+session.getId());
        session.setAttribute("s1","aaaaa");
        String targetUrl= request.getContextPath()+"/f";
        String encodeUrl=response.encodeRedirectURL(targetUrl);
        System.out.println(session.getId());
        response.sendRedirect(encodeUrl);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}


